package com.yidiandao.business.ui.widget.recyclerview.provider;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.data.model.IActiveOrderModel;
import com.yidiandao.business.data.response.ActiveOrderResponse;
import com.yidiandao.business.ui.orderabout.activeorder.detail.ActiveOrderDetailActivity;
import com.yidiandao.business.utils.UIUtils;

import me.drakeet.multitype.ItemViewProvider;

/**
 * 订单活动在进行
 * <p>
 * Created by SunDing(dindding@163.com) on 2017/4/21 12:49
 */
public class ActiveOrderValidProvider extends ItemViewProvider<ActiveOrderResponse.DataBean.EnrollListBean, ActiveOrderValidProvider.ViewHolder> {

    private Activity mActivity;

    public ActiveOrderValidProvider(Activity activity) {

        mActivity = activity;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_active_order_able, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull final ActiveOrderResponse.DataBean.EnrollListBean bean) {
        holder.mTvTitle.setText(bean.getEnrollTitle());
        holder.mTvTime.setText(UIUtils.getString(R.string.active_order_time, bean.getTime()));
        holder.mTvAddress.setText(UIUtils.getString(R.string.active_order_address, bean.getAddress()));

        //状态 0 为支付
        if (bean.getState().equals(IActiveOrderModel.TYPE.VALID)) {
            holder.mTvStatus.setText(Html.fromHtml(UIUtils.getString(R.string.active_order_unPay)));
        } else {
            holder.mTvStatus.setText(UIUtils.getString(R.string.active_order_pay));
        }
        holder.mRlRoot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActiveOrderDetailActivity.actionStart(mActivity, bean.getRecId());
            }
        });
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        private TextView mTvTitle;
        private TextView mTvTime;
        private TextView mTvAddress;
        private TextView mTvStatus;
        private RelativeLayout mRlRoot;

        ViewHolder(View itemView) {
            super(itemView);
            mRlRoot = (RelativeLayout) itemView.findViewById(R.id.rl_root);
            mTvTitle = (TextView) itemView.findViewById(R.id.tv_title);
            mTvTime = (TextView) itemView.findViewById(R.id.tv_time);
            mTvAddress = (TextView) itemView.findViewById(R.id.tv_address);
            mTvStatus = (TextView) itemView.findViewById(R.id.tv_status);

        }
    }
}
